#pragma once
#include"AABB.h"
#include "Hittable.h"
#include "HittableList.h"

class CBVHNode : public CHittable {
public:
	CBVHNode(std::vector<shared_ptr<CHittable>>& vObjects, size_t vStart, size_t vEnd);
	CBVHNode(CHittableList vList) :CBVHNode(vList.m_Objects, 0, vList.m_Objects.size()) {}
	
	bool hit(const CRay& vR, CInterval vRayT, CHitRecord& vHitRecord)const override;
	
	CAABB boundingBox() const override { return m_BBox; }

private:
	shared_ptr<CHittable> m_Left;
	shared_ptr<CHittable> m_Right;
	CAABB m_BBox;

	static bool __boxCompare(const shared_ptr<CHittable> vA, const shared_ptr<CHittable> vB, int AxisIndex);

	static bool __xCompare(const shared_ptr<CHittable> vA, const shared_ptr<CHittable> vB) { return __boxCompare(vA, vB, 0); }
	static bool __yCompare(const shared_ptr<CHittable> vA, const shared_ptr<CHittable> vB) { return __boxCompare(vA, vB, 1); }
	static bool __zCompare(const shared_ptr<CHittable> vA, const shared_ptr<CHittable> vB) { return __boxCompare(vA, vB, 2); }
};